package com.fit.piris.dao.message.priority;

import java.util.List;

import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.Session;
import org.hibernate.criterion.Order;

import com.fit.piris.entities.message.priority.MessagePriority;

public class MessagePriorityDAOImpl implements MessagePriorityDAO {

	@Inject
	private Session session;

	public boolean save(MessagePriority newMessagePriority) {
		if (newMessagePriority != null) {
			session.save(newMessagePriority);
			return true;
		}
		return false;
	}

	public boolean delete(MessagePriority messagePriority) {
		if (messagePriority != null) {
			session.delete(messagePriority);
			return true;
		}
		return false;
	}

	public boolean update(MessagePriority messagePriority) {
		if (messagePriority != null) {
			session.update(messagePriority);
			return true;
		}
		return false;
	}

	public List<MessagePriority> findAll() {
		return session.createCriteria(MessagePriority.class)
				.addOrder(Order.asc("name")).list();
	}

	public MessagePriority findByID(Long id) {
		if (id != null) {
			return (MessagePriority) session.get(MessagePriority.class, id);
		}
		return null;
	}

	public boolean deleteByID(Long id) {
		if (id != null) {
			MessagePriority m = findByID(id);
			if (m != null) {
				session.delete(m);
				return true;
			}
			return false;
		}
		return false;
	}

}
